﻿using ClassLibrary;
using System;
using System.Collections.Generic;

namespace ConsoleDemo
{
    /// <summary>
    /// C# 6.0， 7.0 新增的内容
    /// </summary>
    public class NewlyAdded
    {
        //public string GetwineGrowingRegion(string countryName, string regionName)
        //{
        //    return countryName + ":" + regionName;
        //}

        public string GetwineGrowingRegion(string countryName, string regionName) => countryName + ":" + regionName;

        public static void IndexerInit()
        {
            var favoriteCities = new Dictionary<int, string>
            {
                { 0, "Oxford" },
                { 1, "Paris" },
                { 2, "Barcelona" }
            };

            var favoriteCities1 = new Dictionary<int, string>
            {
                [0] = "Oxford",
                [1] = "Paris"
            };

            //虽然代码编译没有问题，但它会在运行时抛出 ArgumentOutOfRange 异常。因为 List 对象没有元素，所以你不能对这些不存在的元素赋值。
            var stFavoriteCities = new List<string>();
            stFavoriteCities[0] = "Oxford";
            stFavoriteCities[1] = "Paris";
            stFavoriteCities[2] = "Barcelona";
            Console.WriteLine(stFavoriteCities[2]);


            var customer1 = new Person() { Name = "willem", Age = 35 };
            var customer2 = new Person() { Name = "Sandra", Age = 32 };
            //集合初始化
            var customers = new List<Person>() { customer1, customer2 };
        }

        /// <summary>
        /// 值元组
        /// </summary>
        /// <returns></returns>
        public (string, int) CreateSampleTuple()
        {
            return ("Paul", 39);
        }

        public void UseSampleTuple()
        {
            var myTuple = CreateSampleTuple();
            Console.WriteLine($"Name: {myTuple.Item1}, Age: {myTuple.Item2}");
        }

        /// <summary>
        /// is 运算符 模式匹配
        /// </summary>
        public void IsOperatorDemo()
        {
            ClassB classB = new ClassB();
            if (classB is ClassA classAName)
            {
                //如果检测通过了，classAName 变量立即就可以使用
                Console.WriteLine($"My ClassA's name is {classAName.Field1}");
            }
        }

        public void DestructorDemo()
        {
            Student stu = new Student()
            {
                LastName = "鹿"
            };
            Console.WriteLine(stu.LastName);

        }
    }
}
